package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	fmt.Println("-----------------------------------------------")
	file, err := os.OpenFile("./hello1.txt", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0666)
	if err != nil {
		fmt.Println(err)
		return
	}
	defer func(file *os.File) {
		err := file.Close()
		if err != nil {
			fmt.Println(err)
		}
	}(file)

	writer := bufio.NewWriter(file)
	_, err = writer.WriteString("Hello World\r\n")
	if err != nil {
		fmt.Println(err)
		return
	}
	err = writer.Flush()
	if err != nil {
		fmt.Println(err)
		return
	}
}
